<script type="text/javascript">
$(function(){	
	function loading_show()
	{
		$('#loading').html("<img src='images/ajax_load.gif'/>").fadeIn('fast');
	}
	
	function loading_hide()
	{
		$('#loading').fadeOut();
	} 
	
	function loadGallery(roomtypeid)
	{
		loading_show(); 
		$.ajax
		({
			type: "POST",
			url: "ajaxfile.php",
			data: "roomtypeid="+roomtypeid+"&page=load_gallery",
			success: function(msg)
			{
				
					loading_hide();
					
						
					/*$.getScript('http://code.jquery.com/jquery-1.9.1.js');
					$.getScript('http://code.jquery.com/ui/1.10.3/jquery-ui.js');
					$.getScript('js/jquery.nicescroll.min.js');
					$.getScript('js/owl.carousel.js');
					$.getScript('sample.js');
					
					$("#gallery_slider").html(msg);*/
						
			}
		});
	}
	function loadDesc(roomtypeid)
	{
		$.ajax
		({
			type: "POST",
			url: "ajaxfile.php",
			data: "roomtypeid="+roomtypeid+"&count=part&page=load_room_description",
			success: function(data)
			{
				
				$("#innerroomdesc").html(data);							
			}
		});
		
	}
	function loadFacilities(roomtypeid)
	{
		$.ajax
		({
			type: "POST",
			url: "ajaxfile.php",
			data: "roomtypeid="+roomtypeid+"&count=part&page=load_facilities",
			success: function(data)
			{
				
				$("#loadfacilities").html(data);							
			}
		});
		
	}
	function loadExtraFeatures(roomtypeid)
	{
		$.ajax
		({
			type: "POST",
			url: "ajaxfile.php",
			data: "roomtypeid="+roomtypeid+"&count=part&page=load_extra_features",
			success: function(data)
			{
				
				$("#loadextrafeatures ul").html(data);							
				$( ".extras").click(function() {	
	
					var room_type=$("#room_type").val();
					var roomoffers=$("#roomoffers").val();	
					var extrasSelected = new Array();
					var total = parseInt(0);
					
					$('.loadextrafeatures input:checked').each(function() {		
						
						extrasSelected.push($(this).attr('title'));					
						
					});	
					
					for (var i=0;i<extrasSelected.length;i++)
						{
						total += parseInt(extrasSelected[i]);
						}	
					
					loadTotalPrice(room_type,total,roomoffers);
					
					
					});
			}
		});
		
	}
	
	function loadOffers(roomtypeid)
	{
		
		$.ajax
		({
			type: "POST",
			url: "ajaxfile.php",
			data: "roomtypeid="+roomtypeid+"&page=load_offers",
			success: function(data)
			{							
				$("select#roomoffers").html(data);											
			}
		});
		
	}
	
	function loadOffersGallery(roomtypeid)
	{
		$.ajax
		({
			type: "POST",
			url: "ajaxfile.php",
			data: "roomtypeid="+roomtypeid+"&count=part&page=load_offers_gallery",
			success: function(data)
			{
				
				$("#loadextrafeatures").html(data);							
			}
		});
		
	}
	function loadOffersDesc(room_detail)
	{
		var room=room_detail.split('_');
		var offerid=room[0];
		var roomtypeid=room[1];
				
		$.ajax
		({
			type: "POST",
			url: "ajaxfile.php",
			data: "roomtypeid="+roomtypeid+"&offerid="+offerid+"&page=load_offers_desc",
			success: function(data)
			{
				
				$("#roomofferdesc").html(data);							
			}
		});
		
	}
	function OfferPrice(room_type_id,offer_id)
	{		
				
		$.ajax
		({
			type: "POST",
			url: "ajaxfile.php",
			data: "room_type_id="+room_type_id+'&offer_id='+offer_id+"&page=offer_price",
			success: function(data)
			{
				
				$("#savedcost").html(data);
				$("#total_saved_text").attr('value',data);							
			}
		});
	
		
	}
	function loadTotalPrice(room_type_id,extrasPrice,offerPrice)
	{		
				
		$.ajax
		({
			type: "POST",
			url: "ajaxfile.php",
			data: "room_type_id="+room_type_id+"&extrasPrice="+extrasPrice+"&offerPrice="+offerPrice+"&page=load_total_price",
			success: function(data)
			{
				
				
				$("#totalcost").html(data);
				$("#total_price_text").attr('value',data);							
			}
		});
	
		
	}
	
	function TotalByCurrency(currency,totalcost)
	{
		
		$.ajax
		({
			type: "POST",
			url: "ajaxfile.php",
			data: "totalcost="+totalcost+"&currency="+currency+"&page=change_total_by_currency",
			success: function(data)
			{	
				$("#total_price_text").attr('value',data);
				$("#totalcost").html(data);
				
					
			}
		});	
	}
	function SavePriceByCurrency(currency,totalsaved)
	{
		$.ajax
		({
			type: "POST",
			url: "ajaxfile.php",
			data: "currency="+currency+"&totalsaved="+totalsaved+"&page=change_saved_by_currency",
			success: function(data)
			{	
				$("#total_saved_text").attr('value',data);
				$("#savedcost").html(data);
					
			}
		});	
	}
	
	
	$( "#roomtype_descp" ).click(function() {
		var roomtypeid=$(this).attr('alt');
		$.ajax
		({
			type: "POST",
			url: "ajaxfile.php",
			data: "roomtypeid="+roomtypeid+"&count=full&page=load_room_description",
			success: function(data)
			{
				
				$("#room_description_text").html(data)
				$("#div_descp_popup").show();				
			}
		});
 		 
	});
	
	$( "#room_type").change(function() {		
		var roomtypeid=$(this).val();	
				
		loadGallery(roomtypeid);
		loadDesc(roomtypeid);
		loadFacilities(roomtypeid);
		loadExtraFeatures(roomtypeid);
		loadOffers(roomtypeid);
		loadOffersDesc('1_'+roomtypeid);		
		loadTotalPrice(roomtypeid,'0','0');	
		OfferPrice(roomtypeid,'');
 		 
	});
	
	$( "#roomoffers" ).change(function() {		
		var offerid=$(this).val();
		var roomtypeid=$('#room_type').val();
		
		var extrasSelected = new Array();
		var total = parseInt(0);
		$('.loadextrafeatures input:checked').each(function() {		
		
		extrasSelected.push($(this).attr('title'));				
									
		});	
		
		for (var i=0;i<extrasSelected.length;i++)
    	{
        total += parseInt(extrasSelected[i]);
   		}	
		
		
		loadOffersDesc(offerid);		
		
		loadTotalPrice(roomtypeid,total,offerid);	
 		 
		OfferPrice(roomtypeid,offerid); 
	});
	
	$( "#save_booking").click(function() {		
		var hotelid=$("#hetelId").val();		
		var room_type=$("#room_type").val();
		var roomoffers=$("#roomoffers").val();
		var totalcost=$("#total_price_text").val();
		var totalsaved=$("#total_saved_text").val();
		
		var selected = new Array();
				
		$('#loadextrafeatures input:checked').each(function() {
			selected.push($(this).attr('value'));
		});
		var datepicker_form	=$("#datepicker_form").val();
		var datepicker_to	=$("#datepicker_to").val();		
		
		if(datepicker_form!='' && datepicker_to !='')
		{
		$.ajax
		({
			type: "POST",
			url: "save_to_cart.php",
			data: "hotelid="+hotelid+"&room_type="+room_type+"&roomoffers="+roomoffers+"&selected="+selected+"&datepicker_form="+datepicker_form+"&datepicker_to="+datepicker_to+"&totalcost="+totalcost+"&totalsaved="+totalsaved,
			success: function(data)
			{	
				//$('#test').html(data);
				if(data=='y')
				{
					
					 document.location.reload();
					
				}
				else if(data=='n')
				{
					$("#div_booking_failure_popup").show();
				}
					
			}
		});	
		}
		else
		{
			if(datepicker_form=='')
			{
			$("#datepicker_form").css({"border": "1px solid #F00"});
			}
			if(datepicker_to=='')
			{
			$("#datepicker_to").css({"border": "1px solid #F00"});
			}
		}
	});
	
	$( "#book_now").click(function() {			
		
		var hotelid=$("#hetelId").val();		
		var room_type=$("#room_type").val();
		var roomoffers=$("#roomoffers").val();
		var totalcost=$("#total_price_text").val();
		var totalsaved=$("#total_saved_text").val();
		
		var selected = new Array();
				
		$('#loadextrafeatures input:checked').each(function() {
			selected.push($(this).attr('value'));
		});
		var datepicker_form	=$("#datepicker_form").val();
		var datepicker_to	=$("#datepicker_to").val();		
		$.ajax
		({
			type: "POST",
			url: "save_to_cart.php",
			data: "hotelid="+hotelid+"&room_type="+room_type+"&roomoffers="+roomoffers+"&selected="+selected+"&datepicker_form="+datepicker_form+"&datepicker_to="+datepicker_to+"&totalcost="+totalcost+"&totalsaved="+totalsaved,
			success: function(data)
			{					
				if(data=='y')
				{
					 window.location.href='personal_info.php?hotelname=<?php echo $_REQUEST['hotelname'];?>';
				}
				else if(data=='n')
				{
					$("#div_booking_failure_popup").show();
				}
					
			}
		});									 		 
	});
	$( ".extras").click(function() {	
	
	var room_type=$("#room_type").val();
	var roomoffers=$("#roomoffers").val();	
	var extrasSelected = new Array();
	var total = parseInt(0);
	
	$('.loadextrafeatures input:checked').each(function() {		
		
		extrasSelected.push($(this).attr('title'));					
		
	});	
	
	for (var i=0;i<extrasSelected.length;i++)
    	{
        total += parseInt(extrasSelected[i]);
   		}	
	
	loadTotalPrice(room_type,total,roomoffers);
	
	
	});
	$( "#finalbooking").click(function() {			
		
		var hotelid=$("#hetelId").val();		
		var room_type=$("#room_type").val();
		var roomoffers=$("#roomoffers").val();
		var totalcost=$("#total_price_text").val();
		var totalsaved=$("#total_saved_text").val();
		
		var selected = new Array();
				
		$('#loadextrafeatures input:checked').each(function() {
			selected.push($(this).attr('value'));
		});
		var datepicker_form	=$("#datepicker_form").val();
		var datepicker_to	=$("#datepicker_to").val();		
		$.ajax
		({
			type: "POST",
			url: "save_to_cart.php",
			data: "hotelid="+hotelid+"&room_type="+room_type+"&roomoffers="+roomoffers+"&selected="+selected+"&datepicker_form="+datepicker_form+"&datepicker_to="+datepicker_to+"&totalcost="+totalcost+"&totalsaved="+totalsaved,
			success: function(data)
			{	
				//alert(data);
				//$("#test").html(data);
				if(data=='y')
				{
					 window.location.href='personal_info.php';
				}
				else if(data=='n')
				{
					$("#div_booking_failure_popup").show();
				}
					
			}
		});									 		 
	});	
	
	$( "#getCurrency").change(function() {	
	
		var currency=$(this).val();		
		
		var totalcost=$("#total_price_text").val();
		var totalsaved=$("#total_saved_text").val();
		
			TotalByCurrency(currency,totalcost);
			SavePriceByCurrency(currency,totalsaved);
										 		 
	});	
	

});
</script>